package one.saunfa.saunfa.stack;

/**
 * @author wang fei
 * @date 2020-10-12 18:06
 * stack栈
 */

public class MyStack {
    /**
     * 栈数组
     */
    private int [] array;
    /**
     * 栈的大小
     */
    private int maxSize;
    /**
     * 顶栈
     */
    private int top;


    public MyStack(int size){
        this.maxSize = size;
        array = new int [size];
        top = -1;
    }

    //压入数据
    public void push(int value){
        if(top < maxSize -1){
            array[++top] = value;
        }
    }

    //弹出栈项数据
    public int pop(){
        return array[top--];
    }

    //访问栈项数据
    public int peek(){
        return array[top];
    }

    //判断栈是否为空
    public boolean isEmpty(){
        return (top == -1);
    }

    //判断栈是否满了
    public boolean isFull(){
        return (top == maxSize -1);
    }

}
